# !/usr/bin/env python
# coding: utf-8

from flask import Flask
from configs import current_config
from flask_redis import FlaskRedis
from flask_sqlalchemy import SQLAlchemy

"""redis连接实例是线程安全的，可以直接将redis连接实例设置为一个全局变量，直接使用"""
redis_store = FlaskRedis()
db = SQLAlchemy()


def create_app():
    app = Flask(__name__)
    app.config.from_object(current_config)
    current_config.init_app(app)

    redis_store.init_app(app)
    db.init_app(app)

    from .error import error as main_blueprint
    app.register_blueprint(main_blueprint)
    from .api_1_0 import api as api_blueprint
    app.register_blueprint(api_blueprint)

    return app
